/** This example show how to use the static member functions. No session or stream object
    needs to be created or destroyed explicitly.

    Note that, in a multi-threaded application this will be slower as the access to global
    structures need to be synchronized.
 */
#include <iostream>
#include <cstdlib>

#include <kotf/kotf.hpp>

using namespace std;
using namespace kotf;

kotf::State fibo_st;

unsigned fibo(unsigned n)
{
    Scope local(fibo_st);
    
    if (n < 2)
        return n;
    return fibo(n-1) + fibo(n-2);
}

int main(int argc, char **argv)
{
    Session::setDefault("fibonacci2");

    fibo_st = Session::getDefault().getState("fibo");

    Scope local("main");

    unsigned n = 5;

    if (argc == 2)
        n = strtoul(argv[1], 0, 0);
    
    unsigned f = fibo(n);
    cout << "Fibonacci(" << n << ") = " << f << endl;
}

